package com.xxl.servlet;

import com.xxl.dao.VerifyUserDao;
import com.xxl.dao.impl.VerifyUserDaoImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/login")
public class LoginServlet extends HttpServlet {
    VerifyUserDao verifyUserDao = new VerifyUserDaoImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String userName = req.getParameter("userName");
        String password = req.getParameter("password");
        boolean flag  = verifyUserDao.verifyUserNameAndPassword(userName, password);
        if (flag){
            req.getRequestDispatcher("/WEB-INF/main.jsp").forward(req,resp);
        }else {
            resp.sendRedirect("welcome.jsp");
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}
